package cn.wolfcode.producer._01_hello;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("wolfcode_producer");
        //2.设置nameSrv地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动生产者
        producer.start();
        //4.设置发送的消息(默认是同步消息)
        Message message = new Message("01_hello","你好啊rocketMQ".getBytes());
        //5.生产者对象发送消息
        SendResult send = producer.send(message);
        System.out.println(send.getSendStatus());
        //6.关闭连接
        producer.shutdown();
    }
}
